<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/7/25
 * Time: 17:41
 */

namespace Weixin\Service;


use Common\Common\Service;
use Weixin\Component\User_weixin\UserWeixinComponent;
use Weixin\Exception\WeixinException;
use Weixin\Request\User_weixin\GetUserIdRequest;
use Weixin\Response\GetUserIdResponse;

class GetUserIdService implements Service
{
    public function run(GetUserIdRequest $request = null)
    {
        $weixin_id = $request->getWeixinId();
        $component = new UserWeixinComponent();
        $response = new GetUserIdResponse();
        try {
            $result = $component->getUserId($weixin_id);
            $user_id = $result['user_id'];
            if (is_null($user_id) == true) {
                $response->setItIsNull();
            } else {
                $response->setUserId($user_id);
            }
        } catch (WeixinException $e) {
            throw new WeixinException($e->getMessage(), $e->getCode());
        }
        return $response;
    }
}